From: Yehuda Katz + Carl Lerche Date: Wed, 11 Jun 2014 22:59:18 +0000 (-0700) Subject: Sources are now an array X-Git-Tag: archive/raspbian/0.35.0-2+rpi1~3^2^2^2^2^2^2^2~1018 X-Git-Url: https://dgit.raspbian.org/%22http://www.example.com/cgi/success//%22http:/www.example.com/cgi/success/?a=commitdiff_plain;h=51c9cf0f874ac1f10333a171999537db6ff3f1d4;p=cargo.git Sources are now an array --- diff --git a/src/cargo/core/mod.rs b/src/cargo/core/mod.rs index 6fe7ff9c9..781d20087 100644 --- a/src/cargo/core/mod.rs +++ b/src/cargo/core/mod.rs @@ -18,7 +18,8 @@ pub use self::package_id::{ }; pub use self::source::{ - Source + Source, + SourceSet }; pub use self::summary::{ diff --git a/src/cargo/core/package.rs b/src/cargo/core/package.rs index ff83846a7..6c9ef6a7e 100644 --- a/src/cargo/core/package.rs +++ b/src/cargo/core/package.rs @@ -20,7 +20,7 @@ pub struct Package { // The package's manifest manifest: Manifest, // The root of the package - root: Path, + manifest_path: Path, } #[deriving(Encodable)] @@ -30,7 +30,7 @@ struct SerializedPackage { dependencies: Vec, authors: Vec, targets: Vec, - root: String + manifest_path: String } impl> Encodable for Package { @@ -45,16 +45,16 @@ impl> Encodable for Package { dependencies: summary.get_dependencies().iter().map(|d| SerializedDependency::from_dependency(d)).collect(), authors: Vec::from_slice(manifest.get_authors()), targets: Vec::from_slice(manifest.get_targets()), - root: self.root.display().to_str() + manifest_path: self.manifest_path.display().to_str() }.encode(s) } } impl Package { - pub fn new(manifest: &Manifest, root: &Path) -> Package { + pub fn new(manifest: &Manifest, manifest_path: &Path) -> Package { Package { manifest: manifest.clone(), - root: root.clone() + manifest_path: manifest_path.clone() } } @@ -90,8 +90,12 @@ impl Package { self.get_manifest().get_targets() } - pub fn get_root<'a>(&'a self) -> &'a Path { - &self.root + pub fn get_manifest_path<'a>(&'a self) -> &'a Path { + &self.manifest_path + } + + pub fn get_root<'a>(&'a self) -> Path { + self.manifest_path.dir_path() } pub fn get_target_dir<'a>(&'a self) -> &'a Path { diff --git a/src/cargo/core/source.rs b/src/cargo/core/source.rs index c77caa30c..63ee91e52 100644 --- a/src/cargo/core/source.rs +++ b/src/cargo/core/source.rs @@ -36,10 +36,19 @@ pub trait Source { fn get(&self, packages: &[PackageId]) -> CargoResult>; } -impl Source for Vec> { +pub struct SourceSet { + sources: Vec> +} + +impl SourceSet { + pub fn new(sources: Vec>) -> SourceSet { + SourceSet { sources: sources } + } +} +impl Source for SourceSet { fn update(&self) -> CargoResult<()> { - for source in self.iter() { + for source in self.sources.iter() { try!(source.update()); } @@ -49,7 +58,7 @@ impl Source for Vec> { fn list(&self) -> CargoResult> { let mut ret = Vec::new(); - for source in self.iter() { + for source in self.sources.iter() { ret.push_all(try!(source.list()).as_slice()); } @@ -57,7 +66,7 @@ impl Source for Vec> { } fn download(&self, packages: &[PackageId]) -> CargoResult<()> { - for source in self.iter() { + for source in self.sources.iter() { try!(source.download(packages)); } @@ -67,7 +76,7 @@ impl Source for Vec> { fn get(&self, packages: &[PackageId]) -> CargoResult> { let mut ret = Vec::new(); - for source in self.iter() { + for source in self.sources.iter() { ret.push_all(try!(source.get(packages)).as_slice()); } diff --git a/src/cargo/ops/cargo_compile.rs b/src/cargo/ops/cargo_compile.rs index d68543a12..e43200a16 100644 --- a/src/cargo/ops/cargo_compile.rs +++ b/src/cargo/ops/cargo_compile.rs @@ -17,7 +17,7 @@ use std::os; use util::config; use util::config::{ConfigValue}; -use core::{PackageSet,Source}; +use core::{Package,PackageSet,Source,SourceSet}; use core::resolver::resolve; use sources::path::PathSource; use ops; @@ -28,29 +28,16 @@ pub fn compile(manifest_path: &Path) -> CargoResult<()> { // TODO: Move this into PathSource let package = try!(PathSource::read_package(manifest_path)); - debug!("loaded package; package={}", package); - let configs = try!(config::all_configs(os::getcwd())); - - debug!("loaded config; configs={}", configs); - - let config_paths = configs.find_equiv(&"paths").map(|v| v.clone()).unwrap_or_else(|| ConfigValue::new()); - - let mut paths: Vec = match config_paths.get_value() { - &config::String(_) => return Err(other_error("The path was configured as a String instead of a List")), - &config::List(ref list) => list.iter().map(|path| Path::new(path.as_slice())).collect() - }; + let sources = try!(sources_for(&package)); - paths.push(Path::new(manifest_path).dir_path()); - - let source = PathSource::new(paths); - let summaries = try!(source.list().wrap("unable to list packages from source")); + let summaries = try!(sources.list().wrap("unable to list packages from source")); let resolved = try!(resolve(package.get_dependencies(), &summaries).wrap("unable to resolve dependencies")); - try!(source.download(resolved.as_slice()).wrap("unable to download packages")); + try!(sources.download(resolved.as_slice()).wrap("unable to download packages")); - let packages = try!(source.get(resolved.as_slice()).wrap("unable to get packages from source")); + let packages = try!(sources.get(resolved.as_slice()).wrap("unable to get packages from source")); log!(5, "fetch packages from source; packages={}; ids={}", packages, resolved); @@ -60,3 +47,25 @@ pub fn compile(manifest_path: &Path) -> CargoResult<()> { Ok(()) } + +fn sources_for(package: &Package) -> CargoResult { + let sources = try!(sources_from_config([package.get_manifest_path().dir_path()])); + Ok(SourceSet::new(sources)) +} + +fn sources_from_config(additional: &[Path]) -> CargoResult>> { + let configs = try!(config::all_configs(os::getcwd())); + + debug!("loaded config; configs={}", configs); + + let config_paths = configs.find_equiv(&"paths").map(|v| v.clone()).unwrap_or_else(|| ConfigValue::new()); + + let mut paths: Vec = match config_paths.get_value() { + &config::String(_) => return Err(other_error("The path was configured as a String instead of a List")), + &config::List(ref list) => list.iter().map(|path| Path::new(path.as_slice())).collect() + }; + + paths.push_all(additional); + + Ok(vec!(box PathSource::new(paths) as Box)) +} diff --git a/src/cargo/ops/cargo_read_manifest.rs b/src/cargo/ops/cargo_read_manifest.rs index 97ea1755d..1d0f8c4c4 100644 --- a/src/cargo/ops/cargo_read_manifest.rs +++ b/src/cargo/ops/cargo_read_manifest.rs @@ -14,5 +14,5 @@ pub fn read_package(path: &Path, namespace: &Url) -> CargoResult { let data = try!(file.read_to_end().map_err(io_error)); let manifest = try!(read_manifest(data.as_slice(), namespace)); - Ok(Package::new(&manifest, &path.dir_path())) + Ok(Package::new(&manifest, path)) } diff --git a/src/cargo/ops/cargo_rustc.rs b/src/cargo/ops/cargo_rustc.rs index 6e2925cbd..957302f7d 100644 --- a/src/cargo/ops/cargo_rustc.rs +++ b/src/cargo/ops/cargo_rustc.rs @@ -39,7 +39,7 @@ fn compile_pkg(pkg: &Package, dest: &Path, deps_dir: &Path, primary: bool) -> Ca for target in pkg.get_targets().iter() { // Only compile lib targets for dependencies if primary || target.is_lib() { - try!(rustc(pkg.get_root(), target, dest, deps_dir, primary)) + try!(rustc(&pkg.get_root(), target, dest, deps_dir, primary)) } } @@ -52,6 +52,8 @@ fn mk_target(target: &Path) -> CargoResult<()> { } fn rustc(root: &Path, target: &Target, dest: &Path, deps: &Path, verbose: bool) -> CargoResult<()> { + log!(5, "root={}; target={}; dest={}; deps={}; verbose={}", root.display(), target, dest.display(), deps.display(), verbose); + let rustc = prepare_rustc(root, target, dest, deps); try!((if verbose { diff --git a/tests/test_cargo_compile.rs b/tests/test_cargo_compile.rs index deeb20fbc..1fad32a04 100644 --- a/tests/test_cargo_compile.rs +++ b/tests/test_cargo_compile.rs @@ -20,7 +20,7 @@ fn basic_bin_manifest(name: &str) -> String { "#, name, name) } -test!(cargo_compile { +test!(cargo_compile_simple { let p = project("foo") .file("Cargo.toml", basic_bin_manifest("foo").as_slice()) .file("src/foo.rs", main_file(r#""i am foo""#, []).as_slice());